package controller;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class CryptoTool {
	
	public static String md5(String text) throws NoSuchAlgorithmException {
		
		MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(text.getBytes());
        byte[] result = md5.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i=0; i<result.length; i++) {
           String hexStr = Integer.toHexString(0xFF & result[i]);
           if (hexStr.length() == 1)
        	   hexString.append("0");
        	
           hexString.append(Integer.toHexString(0xFF & result[i]));
        }
       
       return hexString.toString();
	}
}
